/* MOS                                                        */
/* Giordano Mion, Luca David Opromolla and Alessandro Sforza  */
/* University of Sussex, Banco de Portugal & NC State, and Bologna       */

program drop _all
clear all
clear matrix
capture log close
set more off
local path = "/Users/lucadavidopromolla/Projects/MOS_rev"
cd "`path'/computation"
log using "`path'/logs/MOS_exp_entry_May_4_2022_rev.log", replace
set mem 12g
set matsize 7500


/////////////////////////////////////
//////////// Prepare data ///////////
/////////////////////////////////////


// 1. Prepare data for firm-destination-year regressions

// Load data and merge with common dataset (to use same set of observations in all regressions, by product and by destination)
use MMT_trade_status_entryb_s.dta, clear
merge m:1 empresa ano using common_dataset
keep if _merge==3
drop _merge
cap drop __000000
sort empresa ano
merge m:1 empresa ano using warexp_data
keep if _merge==3
drop _merge
label var warexp "Mg. w/ Conflict Exp. (0/1)"
egen firm_year_tag = tag(empresa ano)
save ang,replace


// Standardize variables (using the common sample standard deviation at the firm-year-level for firm-year variables and at the firm-year-destination-level for specific export experience)
local ctr_exp_mfs = "relsize relapp_lbprod ln_firmage foreign sh_skilled relmean_age relsd_age relmean_educ relsd_educ"
//foreach x of varlist `ctr_exp_mfs' warexp {
foreach x of varlist `ctr_exp_mfs' {
sum `x' if firm_year_tag==1
replace `x' = `x'/r(sd)
}
save MMT_trade_status_entryb_basic,replace
keep if dest==8
egen nobs = count(ano),by(empresa)
tab nobs
keep if nobs==10
keep empresa
sort empresa
save bsample,replace

use MMT_trade_status_entryb_basic,clear

// Prepare Entry Dummy and Other Variables
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
sort empresa dest ano
gen entry2 = (de_[_n+1]==1 & de_==1 & de_[_n-1]==0 & empresa[_n+1]==empresa & empresa==empresa[_n-1] & dest[_n+1]==dest & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
sort empresa dest ano
gen lmkt_spec_exp = mkt_spec_exp[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2mkt_spec_exp = mkt_spec_exp[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3mkt_spec_exp = mkt_spec_exp[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano
gen lwarexp = warexp[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2warexp = warexp[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3warexp = warexp[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano

sort empresa dest ano
forvalues i=1997/2005 {
gen byte y`i' = ano==`i'
gen byte y`i'_ang = (ano==`i')*(dest==8)
gen inta`i' = mkt_spec_exp*(ano>=`i')
gen linta`i' = lmkt_spec_exp*(ano>=`i')
gen inta`i'_ang = mkt_spec_exp*(ano>=`i')*(dest==8)
gen inta`i'_oect = mkt_spec_exp*(ano>=`i')*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta`i'_oec = max(inta`i'_oect),by(empresa ano)
gen linta`i'_ang = lmkt_spec_exp*(ano>=`i')*(dest==8)
gen l2inta`i' = l2mkt_spec_exp*(ano>=`i')
gen l2inta`i'_ang = l2mkt_spec_exp*(ano>=`i')*(dest==8)
gen l3inta`i' = l3mkt_spec_exp*(ano>=`i')
gen l3inta`i'_ang = l3mkt_spec_exp*(ano>=`i')*(dest==8)
gen winta`i' = warexp*(ano>=`i')
gen lwinta`i' = lwarexp*(ano>=`i')
gen l2winta`i' = l2warexp*(ano>=`i')
gen l3winta`i' = l3warexp*(ano>=`i')
label var inta`i'_ang "Manag. w/ Angola Exp. * Year>=`i' (0/1)"
label var winta`i' "Mg. w/ Conflict Exp. * Year>=`i' (0/1)"
}
gen mkt_spec_exp_ang = mkt_spec_exp*(dest==8)
gen mkt_spec_exp_oect = mkt_spec_exp*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen mkt_spec_exp_oec = max(mkt_spec_exp_oec),by(empresa ano)
label var mkt_spec_exp_ang "Manag. w/ Angola Exp."
gen ang = dest==8
gen lmkt_spec_exp_ang = lmkt_spec_exp*(dest==8)
gen l2mkt_spec_exp_ang = l2mkt_spec_exp*(dest==8)
gen l3mkt_spec_exp_ang = l3mkt_spec_exp*(dest==8)
gen inta20023 = mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen inta20045 = mkt_spec_exp*(ano>=2004)*(ano<=2005)
gen linta20023 = lmkt_spec_exp*(ano>=2002)*(ano<=2003)
gen linta20045 = lmkt_spec_exp*(ano>=2004)*(ano<=2005)
gen l2inta20023 = l2mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen l2inta20045 = l2mkt_spec_exp*(ano>=2004)*(ano<=2005)
gen l3inta20023 = l3mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen l3inta20045 = l3mkt_spec_exp*(ano>=2004)*(ano<=2005)


forvalues i=1997/2005 {
label var y`i' "Year `i' (0/1)"
label var inta`i' "Year>=`i' * Manag. w/ Spec. Exp. (0/1)"
}
egen empresa_time = group(empresa ano)
gen od = dest!=8 & dest>=1 & dest<=14 & de_==1
egen nod = sum(od),by(empresa ano)
sort dest empresa ano
gen lnod = nod[_n-1] if empresa==empresa[_n-1] & dest==dest[_n-1]
tab dest_time,gen(yrd)

// Keep Firm-Year Pairs with no exports in t-1 + raw regression
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)

// Prepare Samples
//use MMT_trade_status_entryb_s1.dta, clear
keep if ano>=1997 & ano<=2005
keep if dest==8 | dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14
xtset empresa_time dest
save data_excol,replace
keep if dest==8
xtset empresa ano
save data_ang,replace
keep empresa ano
save dataset_ang,replace


/////////////////////////////////////
//////////// Regressions ////////////
/////////////////////////////////////

// Locals
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label  e(N) nocons"
local ctr_exp_mf = "relsize relapp_lbprod ln_firmage foreign lnod sh_skilled sh_skilled_d relmean_age relsd_age relmean_educ relsd_educ"
local y "y1999 y2000 y2002 y2003 y2004 y2005"
local inta2002 "inta2002"
local inta "inta2002 inta2003 inta2004 inta2005"
local inta_sim "inta20023 inta20045"
local linta_sim "linta20023 linta20045"
local l2inta_sim "l2inta20023 l2inta20045"
local l3inta_sim "l3inta20023 l3inta20045"
local linta "linta2002 linta2003 linta2004 linta2005"
local linta2002 "linta2002"
local linta2002_ang "linta2002_ang"
local y_ang "y1998_ang y1999_ang y2000_ang y2002_ang y2003_ang y2004_ang y2005_ang"
local inta_ang "inta2002_ang inta2003_ang inta2004_ang inta2005_ang"
local linta_ang "linta2002_ang linta2003_ang linta2004_ang linta2005_ang"
local l2inta "l2inta2002 l2inta2003 l2inta2004 l2inta2005"
local l2inta2002 "l2inta2002"
local l2inta2002_ang "l2inta2002_ang"
local l2inta_ang "l2inta2002_ang l2inta2003_ang l2inta2004_ang l2inta2005_ang"
local l3inta "l3inta2002 l3inta2003 l3inta2004 l3inta2005"
local l3inta2002 "l3inta2002"
local l3inta2002_ang "l3inta2002_ang"
local l3inta_ang "l3inta2002_ang l3inta2003_ang l3inta2004_ang l3inta2005_ang"
local winta2002 "winta2002"
local winta "winta2002 winta2003 winta2004 winta2005"
local lwinta "lwinta2002 lwinta2003 lwinta2004 lwinta2005"
local l2winta "l2winta2002 l2winta2003 l2winta2004 l2winta2005"
local l3winta "l3winta2002 l3winta2003 l3winta2004 l3winta2005"
local inta2002_ang "inta2002_ang"

cd "`path'/results"


// A. Destination experience
////////////////////////////

// Full-history experience

// A1. Having a manager with export experience to Angola

// Regular sample
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
reg exports mkt_spec_exp `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_ba_im.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp) 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

// Balanced sample
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg exports mkt_spec_exp `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp) 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')


// A2. Placebo: effect of export experience before the end of the war

// Regular sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
reghdfe exports mkt_spec_exp `y' `inta' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
reghdfe exports mkt_spec_exp `y' `inta2002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
reg exports mkt_spec_exp `y' `inta' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
reg exports mkt_spec_exp `y' `inta2002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

// Balanced sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe exports mkt_spec_exp `y' `inta' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe exports mkt_spec_exp `y' `inta2002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg exports mkt_spec_exp `y' `inta' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg exports mkt_spec_exp `y' `inta2002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize



// A3. Placebo: IV

// Regular sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
xtivreg2 exports (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
su exports mkt_spec_exp `inta2002'  l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta' y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf' if ano==2002
xtivreg2 exports (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first partial(y1999 y2000 y2002 y2003 y2004 y2005)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
ivreg2 exports (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
ivreg2 exports (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Simplified dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
xtivreg2 exports (mkt_spec_exp `inta_sim' = l3mkt_spec_exp `l3inta_sim' l2mkt_spec_exp `l2inta_sim' lmkt_spec_exp `linta_sim') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_ba_sim_im.xls, ctitle("Placebo IV 2") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta_sim') 
outreg2 using tables/table1dw_ctr_ba_sim_im.xls, ctitle("Placebo IV 2") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Simplified dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
ivreg2 exports (mkt_spec_exp `inta_sim' = l3mkt_spec_exp `l3inta_sim' l2mkt_spec_exp `l2inta_sim' lmkt_spec_exp `linta_sim') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_ba_sim_im.xls, ctitle("Placebo IV 2") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta_sim') 
outreg2 using tables/table1dw_ctr_ba_sim_im.xls, ctitle("Placebo IV 2") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

// Balanced sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
xtivreg2 exports (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
xtivreg2 exports (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 exports (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 exports (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Simplified dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
xtivreg2 exports (mkt_spec_exp `inta_sim' = l3mkt_spec_exp `l3inta_sim' l2mkt_spec_exp `l2inta_sim' lmkt_spec_exp `linta_sim') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_sim_im.xls, ctitle("Placebo IV 2") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta_sim') 
outreg2 using tables/table1dw_ctr_bsample_ba_sim_im.xls, ctitle("Placebo IV 2") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Simplified dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 exports (mkt_spec_exp `inta_sim' = l3mkt_spec_exp `l3inta_sim' l2mkt_spec_exp `l2inta_sim' lmkt_spec_exp `linta_sim') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_sim_im.xls, ctitle("Placebo IV 2") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta_sim') 
outreg2 using tables/table1dw_ctr_bsample_ba_sim_im.xls, ctitle("Placebo IV 2") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


// A4. Placebo: OLS, also controlling for experience in conflict countries

// Regular sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
reghdfe exports mkt_spec_exp warexp `inta' `winta' y1998 y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo OLS + war exp.") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta' warexp `winta') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo OLS + war exp.") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
reghdfe exports mkt_spec_exp warexp `inta2002' `winta2002' y1998 y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Placebo OLS + war exp.") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002' warexp `winta2002') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Placebo OLS + war exp.") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

// Balanced sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe exports mkt_spec_exp warexp `inta' `winta' y1998 y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo OLS + war exp.") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta' warexp `winta') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo OLS + war exp.") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe exports mkt_spec_exp warexp `inta2002' `winta2002' y1998 y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Placebo OLS + war exp.") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002' warexp `winta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Placebo OLS + war exp.") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

/*
// A6. OLS with firm-time FE, use all ex-colonies

// Regular sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_excol",clear
keep if ano>=1998 & ano<=2005
reghdfe exports mkt_spec_exp mkt_spec_exp_ang `inta' `inta_ang', absorb(firm_time)  cluster(empresa_time)  tol(0.001)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Firm-Time FE") addtext("Firm-Year FE", X, "Destination-Year FE", X, "OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_ang `inta' `inta_ang') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Firm-Time FE") `instruct' append keep(`ctr_exp_mf')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_excol",clear
keep if ano>=1998 & ano<=2005
reghdfe exports mkt_spec_exp mkt_spec_exp_ang `inta2002' `inta2002_ang', absorb(firm_time)  cluster(empresa_time) tol(0.001)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Firm-Time FE") addtext("Firm-Year FE", X, "Destination-Year FE", X, "OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_ang `inta2002' `inta2002_ang') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Firm-Time FE") `instruct' append keep(`ctr_exp_mf')
estat summarize

// Balanced sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_excol",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe exports mkt_spec_exp mkt_spec_exp_ang `inta' `inta_ang', absorb(firm_time)  cluster(empresa_time)  tol(0.001)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Firm-Time FE") addtext("Firm-Year FE", X, "Destination-Year FE", X, "OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_ang `inta' `inta_ang') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Firm-Time FE") `instruct' append keep(`ctr_exp_mf')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_excol",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe exports mkt_spec_exp mkt_spec_exp_ang `inta2002' `inta2002_ang', absorb(firm_time)  cluster(empresa_time)  tol(0.001)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Firm-Time FE") addtext("Firm-Year FE", X, "Destination-Year FE", X, "OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_ang `inta2002' `inta2002_ang') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Firm-Time FE") `instruct' append keep(`ctr_exp_mf')
estat summarize
*/

// A7. OLS, also use experience in other ex-colonies

// Regular sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
local inta_oec "inta1998_oec inta1999_oec inta2000_oec inta2002_oec inta2003_oec inta2004_oec inta2005_oec"
local inta2002_oec "inta2002_oec"
keep if ano>=1998 & ano<=2005
reghdfe exports mkt_spec_exp mkt_spec_exp_oec `inta' `inta_oec' `y' `ctr_exp_mf', absorb(empresa)  cluster(empresa) tol(0.001)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Exp Other Col") addtext("Firm FE", X, "OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_oec `inta' `inta_oec') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Exp Other Col") `instruct' append keep(`y' `ctr_exp_mf')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
local inta_oec "inta1998_oec inta1999_oec inta2000_oec inta2002_oec inta2003_oec inta2004_oec inta2005_oec"
local inta2002_oec "inta2002_oec"
reghdfe exports mkt_spec_exp mkt_spec_exp_oec `inta2002' `inta2002_oec' `y' `ctr_exp_mf', absorb(empresa)  cluster(empresa) tol(0.001)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Exp Other Col") addtext("Firm FE", X, "OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_oec `inta2002' `inta2002_oec') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Exp Other Col") `instruct' append keep( `y' `ctr_exp_mf')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
local inta_oec "inta1998_oec inta1999_oec inta2000_oec inta2002_oec inta2003_oec inta2004_oec inta2005_oec"
local inta2002_oec "inta2002_oec"
keep if ano>=1998 & ano<=2005
reg exports mkt_spec_exp mkt_spec_exp_oec `inta' `inta_oec' `y' `ctr_exp_mf', cluster(empresa)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Exp Other Col") addtext("OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_oec `inta' `inta_oec') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Exp Other Col") `instruct' append keep( `y' `ctr_exp_mf')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
local inta_oec "inta1998_oec inta1999_oec inta2000_oec inta2002_oec inta2003_oec inta2004_oec inta2005_oec"
local inta2002_oec "inta2002_oec"
reg exports mkt_spec_exp mkt_spec_exp_oec `inta2002' `inta2002_oec' `y' `ctr_exp_mf', cluster(empresa)
outreg2 using tables/table1dw_ba_im.xls, ctitle("Exp Other Col") addtext("OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_oec `inta2002' `inta2002_oec') 
outreg2 using tables/table1dw_ctr_ba_im.xls, ctitle("Exp Other Col") `instruct' append keep( `y' `ctr_exp_mf')
estat summarize

// Balanced sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
local inta_oec "inta1998_oec inta1999_oec inta2000_oec inta2002_oec inta2003_oec inta2004_oec inta2005_oec"
local inta2002_oec "inta2002_oec"
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe exports mkt_spec_exp mkt_spec_exp_oec `inta' `inta_oec' `y' `ctr_exp_mf', absorb(empresa)  cluster(empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Exp Other Col") addtext("Firm FE", X,"OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_oec `inta' `inta_oec') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Exp Other Col") `instruct' append keep( `y' `ctr_exp_mf')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
local inta_oec "inta1998_oec inta1999_oec inta2000_oec inta2002_oec inta2003_oec inta2004_oec inta2005_oec"
local inta2002_oec "inta2002_oec"
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe exports mkt_spec_exp mkt_spec_exp_oec `inta2002' `inta2002_oec' `y' `ctr_exp_mf', absorb(empresa)  cluster(empresa)  tol(0.001)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Exp Other Col") addtext("Firm FE", X,"OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_oec `inta2002' `inta2002_oec') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Exp Other Col") `instruct' append keep( `y' `ctr_exp_mf')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
local inta_oec "inta1998_oec inta1999_oec inta2000_oec inta2002_oec inta2003_oec inta2004_oec inta2005_oec"
local inta2002_oec "inta2002_oec"
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg exports mkt_spec_exp mkt_spec_exp_oec `inta' `inta_oec' `y' `ctr_exp_mf',cluster(empresa)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Exp Other Col") addtext("OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_oec `inta' `inta_oec') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Exp Other Col") `instruct' append keep( `y' `ctr_exp_mf')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
gen double exports = log(v_est_)
keep if ano>=1998 & ano<=2005
local inta_oec "inta1998_oec inta1999_oec inta2000_oec inta2002_oec inta2003_oec inta2004_oec inta2005_oec"
local inta2002_oec "inta2002_oec"
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg exports mkt_spec_exp mkt_spec_exp_oec `inta2002' `inta2002_oec' `y' `ctr_exp_mf',cluster(empresa)
outreg2 using tables/table1dw_bsample_ba_im.xls, ctitle("Exp Other Col") addtext("OLS", X) `instruct' append keep(mkt_spec_exp mkt_spec_exp_oec `inta2002' `inta2002_oec') 
outreg2 using tables/table1dw_ctr_bsample_ba_im.xls, ctitle("Exp Other Col") `instruct' append keep( `y' `ctr_exp_mf')
estat summarize



log close
